<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <input id="c-product_id" disabled class="form-control" name="row[product_id]" type="hidden" value="{$row.productname_id|htmlentities}">
    <input id="c-factory_id" disabled class="form-control" name="row[factory_id]" type="hidden" value="{$row.factory_id|htmlentities}">
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('产品名称')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-product_name" disabled class="form-control" name="row[product_name]" type="text" value="{$row.product_name|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('产品序列号')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-product_code" disabled class="form-control" name="row[product_code]" type="text" value="{$row.product_code|htmlentities}-{$row.producetime|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('所属工厂')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-factory_tile" disabled class="form-control" name="row[factory_tile]" type="text" value="{$row.factory_tile|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('用户收件信息')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-res_address" disabled class="form-control"  name="row[res_address]" type="text" value="{$row.res_address|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('用户物流单号')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-user_shipper_code" disabled class="form-control"  name="row[user_shipper_code]" type="text" value="{$row.user_shipper_code|htmlentities}--{$row.usersend_time|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('用户说明')}:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea id="c-user_content" class="form-control editor" rows="3" name="row[user_content]" cols="30">{$row.user_content|htmlentities}</textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('购买渠道')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-channel_name" disabled class="form-control" name="row[channel_name]" type="text" value="{$row.channel_name|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('店铺名称')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-shop_name" disabled class="form-control" name="row[shop_name]" type="text" value="{$row.shop_name|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('订单编号')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-order_code" disabled class="form-control" name="row[order_code]" type="text" value="{$row.order_code|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('实际购买时间')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-real_pay_time" disabled class="form-control" name="row[real_pay_time]" type="text" value="{$row.real_pay_time|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('用户是否在保')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-work_bao" disabled class="form-control" name="row[work_bao]" type="text" value="{$row.work_bao|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('创建时间')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-createtime" disabled class="form-control" name="row[createtime]" type="text" value="{$row.createtime|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Order_image')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-order_image" class="form-control" size="50" name="row[order_image]" type="text" value="{$row.order_image|htmlentities}">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="faupload-order_image" class="btn btn-danger faupload" data-input-id="c-order_image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-order_image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                    <span><button type="button" id="fachoose-order_image" class="btn btn-primary fachoose" data-input-id="c-order_image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                </div>
                <span class="msg-box n-right" for="c-order_image"></span>
            </div>
            <ul class="row list-inline faupload-preview" id="p-order_image"></ul>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('备注')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-remarks" disabled class="form-control" name="row[remarks]" type="text"  value="{$row.remarks|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('工厂确认收货时间')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-confirm_time" disabled class="form-control" name="row[confirm_time]" type="text" value="{$row.confirm_time|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Detection_content')}:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea id="c-detection_content" class="form-control editor" rows="5" name="row[detection_content]" cols="50">{$row.detection_content|htmlentities}</textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Damage_reason')}:</label>
        <div class="col-xs-12 col-sm-8">
            <!--<input id="c-damage_reason" class="form-control" name="row[damage_reason]" type="number" value="">
           -->
                <div class="radio">
                    {foreach name="reasonList" item="vo"}
                    <label  for="row[damage_reason]-{$key}"><input onfocus = "cs()" id="row[damage_reason]-{$key}" name="row[damage_reason]" type="radio" value="{$key}" {in name="key" value="1"}checked{/in} /> {$vo}</label>
                    {/foreach}
                </div>


        </div>
    </div>
    <!--<div class="form-group" id="cost">
        <label class="control-label col-xs-12 col-sm-2">{:__('Cost')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-cost" class="form-control" step="0.01" name="row[cost]" type="number" value="">
        </div>
    </div>-->
    <!--<div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"><span style="color: red">*</span>{:__('工厂检测维修状态')}:</label>
        <div class="col-xs-12 col-sm-8">
            <select name="row[factory_status]" required id="c-factory_status" class="form-control selectpicker">
                {foreach name="cidList" item="v"}
                <option value="{$key}" {in name="key" value="1"}selected{/in}>{$v}</option>
                {/foreach}
            </select>
        </div>
    </div>-->
    <div class="form-group" id="repair_zl">
        <label class="control-label col-xs-12 col-sm-2">{:__('工厂检测维修状态')}:</label>
        <div class="col-xs-12 col-sm-8">
            <select  id="c-factory_status"  class="form-control selectpicker" multiple="" name="row[factory_status][]">
                <!-- {foreach name="problemList" item="vo"}
                 <option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
                 {/foreach}-->
                {foreach name="repair_zl" item="vo"}
                <option  value="{$key}" {in name="key" value=""}selected{/in}>{$vo.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="form-group"   id="repair_fzl">
        <label class="control-label col-xs-12 col-sm-2">{:__('工厂检测维修状态')}:</label>
        <div class="col-xs-12 col-sm-8" >
            <select  id="c-factory_status"  class="form-control selectpicker" multiple="" name="row[factory_status][]">
                <!-- {foreach name="problemList" item="vo"}
                 <option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
                 {/foreach}-->
                {foreach name="repair_fzl" item="vo"}
                <option  value="{$key}" {in name="key" value=""}selected{/in}>{$vo.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="form-group" id="problem_zl">
        <label class="control-label col-xs-12 col-sm-2"><span style="color: red">*</span>{:__('问题类型')}:</label>
        <div class="col-xs-12 col-sm-8">
            <select  id="c-problem"  class="form-control selectpicker" multiple="" name="row[problem][]">
               <!-- {foreach name="problemList" item="vo"}
                <option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
                {/foreach}-->
                {foreach name="parentList_zl" item="vo"}
                <option  value="{$key}" {in name="key" value=""}selected{/in}>{$vo.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="form-group"   id="problem_fzl">
        <label class="control-label col-xs-12 col-sm-2"><span style="color: red">*</span>{:__('问题类型')}:</label>
        <div class="col-xs-12 col-sm-8" >
            <select  id="c-problem"  class="form-control selectpicker" multiple="" name="row[problem][]">
                <!-- {foreach name="problemList" item="vo"}
                 <option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
                 {/foreach}-->
                {foreach name="parentList_fzl" item="vo"}
                <option  value="{$key}" {in name="key" value=""}selected{/in}>{$vo.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('工厂备注')}:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea id="c-gcremarks" class="form-control editor" rows="5" name="row[gcremarks]" cols="50">{$row.gcremarks|htmlentities}</textarea>
        </div>
    </div>
    <div class="form-group" id="cost_content">
        <label class="control-label col-xs-12 col-sm-2">{:__('Cost_content')}:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea id="c-cost_content" class="form-control editor" rows="3" name="row[cost_content]" cols="30"></textarea>
        </div>
    </div>
    <div class="form-group row">
        <label class="control-label col-xs-12 col-sm-2"><span style="color: red">*</span><?php echo __('费用选择'); ?></label>
        <div>
            <!--data-template的值作为行中的id值，才能便于追加行与引用-->
            <table class="table fieldlist" data-template="linedetail" data-name="row[linedetail]" id="linetable" style="width: 80%;margin-left: 25px">
                <thead>
                <tr class="info">
                    <th>工厂</th>
                    <th>产品名称</th>
                    <th>费用项</th>
                    <th>工厂收取费用</th>
                    <th>心喜阅费用</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody class="lyj_tbody">
                </tbody>
                <tbody>
                <!--name中<%=name%>表示的是data-template为此地的id值linedetail,对应的data-name的值linedetail-->
                <script id="linedetail" type="text/html" name="linedetail">
                    <tr class="active">


                        <td>
                            <input type="text" readonly id="factory_title<%=index+1%>" class="form-control"  data-line="<%=index+1%>" name="<%=name%>[<%=index%>][factory_title]"/>
                        </td>
                        // 料号名称
                        <td>
                            <input type="text" readonly  class="form-control" id="product_name<%=index+1%>" name="<%=name%>[<%=index%>][product_name]"  />
                        </td>
                        // 规格型号
                        <td>
                            <input type="text" readonly class="form-control" id="costmode_name<%=index+1%>" name="<%=name%>[<%=index%>][costmode_name]"  />
                        </td>
                        // 单位
                        <td>
                            <input type="text" readonly onblur = "cost_money()" class="form-control" id="cost_money<%=index+1%>" name="<%=name%>[<%=index%>][cost_money]" style="width: 100px"/>
                        </td>
                        <td>
                            <input type="text" readonly onblur = "cost_money()" class="form-control" id="real_money<%=index+1%>" name="<%=name%>[<%=index%>][real_money]" style="width: 100px"/>
                        </td>
                        <td>
                            <span class="btn btn-sm btn-danger btn-removeline"><i class="fa fa-times"></i></span>
                        </td>
                    </tr>
                </script>


                </tbody>
                <tr>
                    <td>
                        <!--<span data-url="cost/select?product_id=" class="form-control fachoosetable" data-line="<%=index+1%>">选择</span>-->
                    <td colspan="1"><a href="javascript:;" class="btn btn-sm btn-success fachoosetable"><i class="fa fa-plas"></i>选择</a></td>
                    </td>
                   <!-- <td colspan="1"><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plas"></i>添加行</a></td>-->
                    <td colspan="6">{:__('工厂收取费用')}:<input id="all_quantity" type="text" name="row[all_quantity]" readonly="readonly" style="width:80px;border-width:0px"/>{:__('心喜阅费用')}:<input id="all_quantity_real" type="text" name="row[all_quantity_real]" readonly="readonly" style="width:80px;border-width:0px"/></td>
                </tr>
            </table>
            <!--请注意实际开发中textarea应该添加个hidden进行隐藏-->
            <textarea id="textarea1" name="linedetail" class="form-control hidden" cols="30" rows="5"></textarea>
        </div>
    </div>
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
        </div>
    </div>
</form>
<script type="text/javascript">
   /* sss();
   function sss(){
       console.log(23423423423)
       $("#repair_fzl").addClass('hide'); //
       $("#repair_zl").show(); //
   }*/
    function cs () {
        var popVal = $("input[type=radio][name='row[damage_reason]']:checked").val();
        //let id = $("#damage_reason").val();
       // popVal = $(this).val();
       // alert(popVal);
        console.log("进入方法","number ="+popVal);
        if (popVal === '1') {
            // 弹窗公告
            $("#cost").addClass('hide');
            $("#cost_content").addClass('hide');

            $("#problem_fzl").addClass('hide');
            $("#problem_zl").show(); //

            $("#repair_fzl").addClass('hide'); //
            $("#repair_zl").show(); //
        } else {
            // 活动公告
            $("#cost").removeClass('hide');
            $("#cost_content").removeClass('hide');

            $("#problem_fzl").removeClass('hide');
            $("#problem_zl").hide(); // 隐藏
            $("#repair_fzl").removeClass('hide');
            $("#repair_zl").hide(); // 隐藏
        }

    }
    function cost_money () {
        var len = $('#linetable tr').length;
       // alert(len);
        console.info(len);
        var cost_money_sun = 0;
        var real_money_sun = 0;
        for (var i = 1; i < len - 1; i++) {

            var checkbox = document.getElementById('checkbox'+i);
            var isChecked = checkbox.checked;
            console.log("checkbox"+isChecked); // true表示选中，false表示未选中
            var cost_money = $("#cost_money"+i).val();
            var real_money = $("#real_money"+i).val();
            console.log("cost_money"+cost_money);
            if(isChecked == true){
                cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                real_money_sun = Number(real_money_sun) + Number(real_money);
            }

            /*$('#linetable tr:eq(' + i + ') td:first').find('input').val(i);*/
            //查找id为table的表格内索引为i的行中的第一个单元格，然后将索引i设置为文本内容。
            //tr:eq(' + i + ') 是一个用于选择HTML元素的jQuery选择器，意思是选取序号为i的表格行（table row）。
        }
        //alert("总费用"+cost_money_sun);
        //alert("实际费用"+real_money_sun);
        var popVal = $("input[type=radio][name='row[damage_reason]']:checked").val();
        var work_bao = $("#c-work_bao").val();
        $('#all_quantity').val(cost_money_sun);
        if(work_bao == '在保' && popVal == 2){
            real_money_sun = 0;
        }
        $('#all_quantity_real').val(real_money_sun);
    }
    $(document).ready(function(){
        $('#confirmSelection').click(function(){
            // 假设已选中的项保存在一个数组中，如selectedItems
            var selectedItems = []; // 这里填入已选中的项
            // 调用父页面的函数并传递选中的项
            parent.receiveMultipleSelection(selectedItems.join(','));
            // 关闭当前弹窗
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
    });
    $(document).on('click', '.btn-selectMultipleBtn-click', function () {
        let id = $("#c-id").val();
        parent.Fast.api.open('work/detection?ids='+id, __('上传检测报告'),{
            //接收传过来的参数
            callback:function(value){
                //在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
            }
        });
    });

    // 接收多选结果的回调函数
    function receiveMultipleSelection(ids){
        // 使用ajax将选中的ids发送到服务器处理
        $.post('__URL__/selectMultiple', {ids: ids}, function(data){
            // 处理服务器响应
        });
    }
</script>
